<template>
  <div class="xtx-form">
    <div class="user-info">
      <img src="http://qzapp.qlogo.cn/qzapp/101941968/57C7969540F9D3532451374AA127EE5B/50" alt="" />
      <p>Hi，Tom 欢迎来小兔鲜，完成绑定后可以QQ账号一键登录哦~</p>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-phone"></i>
        <input v-model="form.mobile" class="input" type="text" placeholder="绑定的手机号" />
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-code"></i>
        <input v-model="form.code" class="input" type="text" placeholder="短信验证码" />
        <span class="code" @click="sendClick">{{count ? count + 's后再获取' : '发送验证码'}}</span>
      </div>
      <div class="error"></div>
    </div>
    <a href="javascript:;" class="submit">立即绑定</a>
  </div>
</template>

<script>
import { timeOut } from '@/compositions'
import { reqUserQQBindCode } from '@/api/user'
import { reactive } from 'vue-demi'
import { message } from '@/components/Message'

export default {
  name: 'CallbackBind',

  setup () {
    const form = reactive({
      mobile: '',
      code: ''
    })
    const { count, start } = timeOut(6)
    const sendClick = () => {
      if (count.value) {
        return
      }
      if (/^1[3-9]\d{9}$/.test(form.mobile)) {
        reqUserQQBindCode(form.mobile).then(res => {
          start()
          console.log(res)
          console.log('开启倒计时')
        })
      } else {
        message({
          type: 'error',
          text: '请输入合法的手机号'
        })
      }
    }
    return { sendClick, count, form }
  }
}
</script>

<style scoped lang='less'>
.user-info {
    width: 320px;
    height: 70px;
    margin: 0 auto;
    display: flex;
    background: #f2f2f2;
    align-items: center;
    padding: 0 10px;
    margin-bottom: 25px;
    img {
      background: #f2f2f2;
      width: 50px;
      height: 50px;
    }
    p {
      padding-left: 10px;
    }
  }
  .code {
    position: absolute;
    right: 0;
    top: 0;
    line-height: 50px;
    width: 80px;
    color: #999;
    &:hover {
      cursor: pointer;
    }
  }
</style>
